#Reducer Class definition
setClass("Reducer",representation(
				.description="character",
				.dimChooser="DimChooser",
				.tmpData="matrix", #this field contains temporal copy of data during reduce operation
				.resEnv="environment",
				 "VIRTUAL"
		),
		prototype=prototype(
				.description="Virtual Reducer Class",
				.tmpData =matrix()
				))
#generic functions
setGeneric("reduce",function(.Object,inputSet,...){standardGeneric("reduce")})
setGeneric("changeDimChooser",function(.Object,dimChooser,...){standardGeneric("changeDimChooser")})
setGeneric("getSavedSet",function(.Object,...){standardGeneric("getSavedSet")})
setGeneric("cleanSavedSet",function(.Object,...){standardGeneric("cleanSavedSet")})

#methods

#initialization method 
setMethod("initialize",
		signature="Reducer",
		function(.Object,dimChooser,...){
			.Object@.dimChooser <- dimChooser;
			.Object@.resEnv <- new.env()
			return(.Object)
		})

setMethod("get_description",
		signature="Reducer",
		definition=function(.Object){
			paste(.Object@.description,get_description(.Object@.dimChooser),sep=";")
		})
#Returns new object witch changed dimChooser
#you must manually asign modified object to oryginal
setMethod("changeDimChooser",
		signature="Reducer",
		function(.Object,dimChooser,...){
			.Object@.dimChooser <- dimChooser;
			.Object@.resEnv$savedSet <-NULL
			validObject(.Object)
			return(.Object)
		})
setMethod("getSavedSet",
		signature="Reducer",
		definition=function(.Object,...){
			if(exists("savedSet",envir=.Object@.resEnv)){
				return(.Object@.resEnv$savedSet)
			}
			return(NULL)
		})

setMethod("cleanSavedSet",
		signature="Reducer",
		definition=function(.Object,...){
			
				.Object@.resEnv$savedSet <-NULL
			
			
		})


